package engine.gui;

import engine.game.Manager;
import engine.graphics.Color4f;
import engine.graphics.FontManager;

public class ProgressBar extends ParentObject {

	private static final long serialVersionUID = 1L;

	private Panel progress ; 
	private int max = 0 ;
	private int step = 0 ; 

	public ProgressBar(Manager m, int x, int y, int w, int h, int max){
		super(m, x, y, w, h); 
		this.setMax(max);
		init(); 
	}
	
	public ProgressBar(Manager m, ParentObject parent, int w, int h, int max) {
		this(m, (int)parent.getMinX(), (int)parent.getMinY(), w, h, max);
	}

	public void init(){
		super.init(); 
		this.disableHovering();
		this.disableClicking(); 
		this.enableBorder(); 
		this.progress = new Panel(this.getManager(), this, 0, 0);
		this.setProgress(max);
		progress.changeNormalColor(new Color4f(1,0,0,1));
		progress.setFontName(FontManager.S_FONT_13);
		progress.labelPadding(10, 25);
		this.changeNormalColor(new Color4f(0.25f, 0.25f, 0.25f, 0.35f));
		this.addNewChild("progress", progress);
	}
	
	public Panel getProgress() {
		return progress;
	}

	public void setProgress(int value, int max){
		this.setMax(max); 
		this.setProgress(value);
	}
	
	public void setProgress(int value){
		if(value>max) value = max; 
		if(value < max)
			this.progress.changeSize(value*this.step, this.getObjectHeight());
		else
			this.progress.changeSize(this.getObjectWidth(), this.getObjectHeight());
		this.progress.setCaption(String.valueOf(value)+" / "+String.valueOf(max));
	}
	
	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
		this.step = this.getObjectWidth() / max ; 	
	}
	
	
	
}
